package com.appkubes.portal.admin.application.app.role.controller;

import com.appkubes.common.Response;
import com.appkubes.portal.admin.application.app.role.entity.vo.RoleAddVO;
import com.appkubes.portal.admin.application.auth.service.KeyCloakRoleService;
import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.portal.core.service.BasePortalAppRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/app/role")
public class AppRoleController {

    @Resource
    KeyCloakRoleService keyCloakRoleService;

    @ApiOperation("添加角色(不能修改)")
    @PostMapping("/add")
    public Response add(@ParamValid RoleAddVO roleAddVO) {
        RoleRepresentation roleRepresentation = keyCloakRoleService.createClientRole(roleAddVO);
        return Response.success(roleRepresentation);
    }

    @ApiOperation("删除角色(不能修改)")
    @PostMapping("/del/{roleName}")
    public Response del(@PathVariable("roleName") String roleName) {
        Boolean flag = keyCloakRoleService.deleteClientRole(roleName);
        return Response.success(flag);
    }

    @ApiOperation("获取角色列表")
    @GetMapping("/get")
    public Response get() {
        List<?> list = keyCloakRoleService.getClientRoleList();
        return Response.success(list);
    }


}
